<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tab切换栏</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        
        .current {
            background-color: red;
        }
        
        .tab_list ul {
            background-color: grey;
            height: 21px;
            width: 800px;
        }
        
        .tab_list ul li {
            width: 80px;
            margin: auto 20px;
            list-style: none;
            float: left;
        }
        /*隐藏内容*/
        
        .item {
            display: none;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab_list">
            <ul>
                <li class="current">商品介绍</li>
                <li> 规格与保障</li>
                <li>售后保障</li>
                <li>商品评价</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="tab_con">
            <div class="item" style="display: block">
                商品介绍模块
            </div>
            <div class="item">
                规格与保障模块
            </div>
            <div class="item">
                售后保障模块
            </div>
            <div class="item">
                商品评价模块
            </div>
            <div class="item">
                手机社区模块
            </div>
        </div>
    </div>
    <script>
        let tab_list = document.querySelector('.tab_list');
        let lis = tab_list.querySelectorAll('li');
        let items = document.querySelectorAll('.item');
        for (let i = 0; i < lis.length; i++) {
            //开始给5个小li设置索引号
            lis[i].setAttribute('index', i);
            lis[i].onclick = function() {
                for (let i = 0; i < lis.length; i++) {
                    lis[i].className = '';
                }
                this.className = 'current';
                //形式内容模块
                let index = this.getAttribute('index');
                console.log(index);
                for (let i = 0; i < items.length; i++) {
                    items[i].style.display = 'none';
                }
                items[index].style.display = 'block';
            }
        }
    </script>
</body>

</html>